<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>tab栏切换(重点)</title>
    <link rel="shortcut icon" href="bitbug_favicon.ico">
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .clearfix:after {
            content: "";
            display: block;
            height: 0;
            clear: both;
            visibility: hidden;
        }

        .clearfix {
            *zoom: 1;
        }

        ul {
            text-align: center;
        }

        li {
            width: 150px;
            height: 40px;
            line-height: 40px;
            list-style: none;
            float: left;
            margin: 0 10px;
            color: #ccc;
            cursor: pointer;
        }

        .current {
            background-color: red;
        }

        .item {
            display: none;
        }

        .footer {
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translate(-50%);
        }
    </style>
</head>

<body>
    <div class="tab">
        <div class="tab_list">
            <ul class="clearfix">
                <li class="current">商品介绍</li>
                <li>规格与包装</li>
                <li>售后保障</li>
                <li>商品评价（2000）</li>
                <li>手机社区</li>
            </ul>
        </div>
        <div class="tab_con">
            <div class="item" style="display:block;">
                商品介绍模块内容
            </div>
            <div class="item">
                规格与包装模块内容
            </div>
            <div class="item">
                售后保障模块内容
            </div>
            <div class="item">
                商品评价（2000）模块内容
            </div>
            <div class="item">
                手机社区模块内容
            </div>
        </div>
    </div>
    <footer class="footer">
        <a href="http://muxiaosheng.3vzhuji.net/" target="_blank"><img src="http://www.bitbug.net/mypagerank.php?style=20"
                border="0" alt="My Google PageRank" /></a>
    </footer>
    <script>
        var tab_list = document.querySelector('tab_list');
        var lis = document.querySelectorAll('li');
        var items = document.querySelectorAll('.item');
        for (let i = 0; i < lis.length; i++) {
            //开始给5个小li 设置索引号
            lis[i].setAttribute('index', i);
            lis[i].onclick = function () {
                for (let i = 0; i < lis.length; i++) {
                    lis[i].className = '';
                }
                lis[i].className = 'current';
                //2.下面显示内容模块
                var index = this.getAttribute('index');
                // console.log(index);
                for (let i = 0; i < items.length; i++) {
                    items[i].style.display = 'none';
                }
                items[index].style.display = 'block';
            }
        }

    </script>
</body>

</html>